﻿using System;
using System.ComponentModel.Composition;
using Contracts;
using System.Reflection;

namespace WpfAppHost
{
    [WpfServiceMetadata("GeneralAddin")]
    public class GeneralAddinImpl : IWpfServiceAdmin
    {
        string _status;
        public event EventHandler StatusUpdated;

        GeneralConfigUserControl _optionsUI = new GeneralConfigUserControl();

        public GeneralAddinImpl()
        {
            Console.WriteLine("GeneralAddin starting up!");
        }

        public System.Windows.Controls.UserControl OptionsUserControl
        {
            get { return _optionsUI; }
        }

        public string Name
        {
            get { return "General"; }
        }

        public Uri AddinIconUri
        {
            get {
                string u = CreateResourceUri("Settings.png");
                return new Uri(u);
            }
        }

        private string CreateResourceUri(string name)
        {
            Assembly a = Assembly.GetExecutingAssembly();
            return string.Format("pack://application:,,,/{0};component/Resources/{1}", a.GetName().Name, name);
        }

        public string Description
        {
            get { return ""; }
        }

        public string Author
        {
            get { return "Arian T. Kulp"; }
        }

        public Version Version
        {
            get { return Assembly.GetExecutingAssembly().GetName().Version; }
        }

        public Uri AuthorUri
        {
            get { return new Uri("http://www.ariankulp.com/"); }
        }

        public Uri UpdateUri
        {
            get { return new Uri("http://www.ariankulp.com/downloads/"); }
        }

        public string Status
        {
            get { return _status; }
            set
            {
                if (value != _status)
                {
                    _status = value;

                    if (StatusUpdated != null)
                        StatusUpdated(this, null);
                }
            }
        }

        public void Initialize()
        {
            _optionsUI.DataContext = this;
        }

        public void Start()
        {
        }

        public void Stop()
        {
        }

        public IWpfHost ServiceHost
        {
            get;
            set;
        }
    }
}
